#{extends 'main.html'/}
<link rel="stylesheet" href="/public/themes/default/default.css" />
<script charset="utf-8" src="/public/kindeditor-min.js"></script>
<script charset="utf-8" src="/public/lang/zh_CN.js"></script>
<div class="l-clear"></div>
<div id="maingrid" style="margin-top:1px"></div> <br />
<div style="display:none;"></div>
<div id="detail" style="display:none;"><form id="mainform" method="post"></form></div>
<div id="inputForm">
    <form id="inputForms" method="post">
        <table>
            <tr>
                <td>　　编　号：<input type="text" name="expert.id"/></td>
                <td>　　名　字：<input type="text" name="expert.Name" /></td>
                <td><table><tr><td>　　职　称：</td><td><input type="text" id="Type1" /></td></tr></table></td>
                <td><table><tr><td>　职　位：</td><td><input type="text" id="Title1"/></td></tr></table></td>
                <td><table><tr><td>　科　室：</td><td><input type="text" id="dept1" /></td></tr></table></td>
                <td><input type="hidden" name="expert.id"/></td>
            </tr>
            <tr><td>&nbsp;</td></tr>
            <tr>
                <td>　　输入码：<input type="text" name="expert.InputCode" /></td>
                <td><table><tr><td>　人员类别：</td><td><input type="text" id="ExperBit" /></td></tr></table></td> 
                <td>　　序列号：<input type="text" name="expert.SerialNo" /></td> 
                <td>　专家标识：<input type="checkbox" name="expert.MYFlag" value="是" /></td> 
            </tr>
        </table>
        </br>
        <table>
            <tr>
                <td>　专家简介：</td>
                <td><textarea name="expert.Info" id="expertInfo" style="width:720px;height:200px;visibility:hidden;">请输入专家简介内容。。。</textarea></td><td><table>
                        <tr>
                            <td>　　　　照</br>　　　　片</td> <td>　　</td>  <td><image src="/public/Picture/1.png"/></td>
                        </tr>
                    </table></td>
            </tr>
        </table>

    </form>
</div>
<script type="text/javascript">
    $(function () {
        $("[name$=id]").attr('readonly','readonly');
        var manager, grid;
        function f_initGrid() 
        {
            grid = manager = $("#maingrid").ligerGrid({
                columns: [
                    { display: '编号', name: 'id', width: 50, type: 'textarea' },
                    { display: '名字', name: 'Name', width: 100, type: 'textarea' },
                    { display: '职称', name: 'Type.Name', width: 100, type:'textarea'},
                    { display: '职位', name: 'title.Name', width: 120, type: 'string', type: 'textarea'},
                    { display: '科室 ', name: 'dept.Name', width: 120, type: 'string', type: 'textarea'},//这个需要下拉框来选择
                    { display: '输入码', name: 'InputCode', width: 120, type: 'string', type: 'textarea'},
                    { display: '专家标识', name: 'MYFlag', width: 120, type: 'string', type: 'textarea'},
                    { display: '人员类别', name: 'ExperBit', width: 120, type: 'string', type: 'textarea'},
                    { display: '序列号', name: 'SerialNo', width: 120, type: 'string', type: 'textarea'}
                ],

                url: "experts/json",  method: "GET",                       
                width: '100%',height:"48%", 
                toolbar: { items: [
                        { text: '增加', click: addRow, icon: 'add' },
                        { line: true },
                        { text: '保存', click: modifyRow, icon: 'modify' },
                        { line: true },
                        { text: '删除', click: deleteRow, icon: 'delete' },
                        { line: true },
                        { text: '复原', click: replay, icon: 'back' },
                        { line: true }
                    ] }
            });         	
        }
        f_initGrid();
        $("#Type1").ligerComboBox({ 
            url:'headShips/findAll',
            valueField:'id',
            textField:'Name',
            valueFieldID: 'expert.Type.id',
            autocomplete :true
        });
     
        $("#Title1").ligerComboBox({ 
            url:'titles/findAll',
            valueField:'id',
            textField:'Name',
            valueFieldID: 'expert.title.id',
            autocomplete :true
        });
        /*
        $("#dept1").ligerComboBox({
            url:'depts/findAll',
            valueField:'id',
            textField:'Name',
            valueFieldID: 'expert.dept.id'
            // autocomplete :true
        });
        $("#ExperBit").ligerComboBox({
            url:'depts/findAll',
            valueField:'id',
            textField:'Name',
            valueFieldID: 'expert.ExperBit',
            autocomplete :true});*/
        
        grid.bind('selectRow', function (data)
        {
            showDetail(data);
            editor.html(data.Info)
        });
        
        function replay(){
            showDetail({});
             editor.html('')
        }

        function showDetail(data){
            
            if(data != null){
                $("[name$=id]").val(data.id);
                $("[name$=Name]").val(data.Name);
                $("[name$=InputCode]").val(data.InputCode);
                $("[name$=SerialNo]").val(data.SerialNo);
                // $("#dept1").ligerGetComboBoxManager().setValue(data.Name);
                if(data.MYFlag !=null){
                    //$.ligerDialog.alert(data.MYFlag);
                    $("[name$=MYFlag]").attr('checked','checked');
                }else{
                    //$.ligerDialog.alert("2");
                    // $("[name$=MYFlag]").attr('checked','false');
                } 
            }else{
                $("[name$=id]").val();
                $("[name$=Name]").val();
                $("[name$=InputCode]").val();
                $("[name$=SerialNo]").val();
               // $("#expertInfo").val(editor.html(''));
               
            }
            
        }


        function f_reload() {
            grid.loadData();
        }
        
        function getSelected()
        { 
            var row = manager.getSelectedRow();
            if (!row) { alert('请选择行'); return; }
            alert(JSON.stringify(row));
        }
        

        
        function getData()
        { 
            var data = manager.getData();
            alert(JSON.stringify(data));
        }
        
        function addRow()
        {
            save();
        }
        
        function modifyRow()
        {
            var selected = grid.getSelected();
            if (!selected) { LG.tip('请选择行!'); return }
            $("[name$=id]").val(selected.id);
            save();
            
        }
        
        function deleteRow()
        {
            jQuery.ligerDialog.confirm('确定删除吗?', function (confirm) {
                if (confirm) f_delete(); });
        }
        
        function f_delete() {
            var selected = grid.getSelected();
            if (selected) {
                $.ajax({
                    url: 'expert/' + selected.id,
                    type: 'DELETE',                  
                    loading: '正在删除中...',                  
                    success: function () {
                        //LG.showSuccess('删除成功');
                        LG.tip('删除成功!');
                        f_reload();
                    },
                    error: function (message) {
                        LG.showError(message);
                    }
                });
            }
            else {
                LG.tip('请选择行!');
            }
        }
 
        function save()
        {   
            $("#inputForms").validate();
            $("#expertInfo").val(editor.html());
            $.ajax({
                loading: '正在保存数据中...',
                type: 'POST',
                url: 'experts',
                data: $("#inputForms").serialize(),
                success: function ()
                {
                    grid.loadData();
                    LG.tip('保存成功!');
                },
                error: function (message)
                {
                    LG.tip(message);
                }
            });
        }
  
    })
        
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('#expertInfo', {
            allowFileManager : true
        });
        
        /*K('input[name=clear]').click(function(e) {
            editor.html('');
        });*/
				
    });
</script>
